package com.attendance.www.hr.service.impl;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFDateUtil;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Service;

import com.attendance.www.hr.beans.AttendanceBean;
import com.attendance.www.hr.beans.EmployeeBean;
import com.attendance.www.hr.beans.EmployeePunchTimeBean;
import com.attendance.www.hr.beans.RetroactiveBean;
import com.attendance.www.hr.beans.RoleBean;
import com.attendance.www.hr.beans.SchedulWeekBean;
import com.attendance.www.hr.beans.SchedulWeekPageBean;
import com.attendance.www.hr.constant.AppConstant;
import com.attendance.www.hr.dao.mapper.AttachmentMapper;
import com.attendance.www.hr.dao.mapper.DepartmentMapper;
import com.attendance.www.hr.dao.mapper.EmployeeExtMapper;
import com.attendance.www.hr.dao.mapper.EmployeeMapper;
import com.attendance.www.hr.dao.mapper.EmployeeRoleMapper;
import com.attendance.www.hr.dao.mapper.EmployeeSchedulExtMapper;
import com.attendance.www.hr.dao.mapper.EmployeeSchedulMapper;
import com.attendance.www.hr.dao.mapper.HolidayMapper;
import com.attendance.www.hr.dao.mapper.PunchTimeMapper;
import com.attendance.www.hr.dao.mapper.RoleDepartmentMapper;
import com.attendance.www.hr.dao.mapper.RoleMapper;
import com.attendance.www.hr.dao.mapper.SchedulDayMapper;
import com.attendance.www.hr.dao.mapper.SchedulWeekExtMapper;
import com.attendance.www.hr.dao.mapper.SchedulWeekMapper;
import com.attendance.www.hr.dao.mapper.ShiftPermissionExtMapper;
import com.attendance.www.hr.entitys.Attachment;
import com.attendance.www.hr.entitys.Department;
import com.attendance.www.hr.entitys.Employee;
import com.attendance.www.hr.entitys.EmployeeExample;
import com.attendance.www.hr.entitys.EmployeeRole;
import com.attendance.www.hr.entitys.EmployeeRoleExample;
import com.attendance.www.hr.entitys.EmployeeSchedul;
import com.attendance.www.hr.entitys.EmployeeSchedulExample;
import com.attendance.www.hr.entitys.Holiday;
import com.attendance.www.hr.entitys.HolidayExample;
import com.attendance.www.hr.entitys.PunchTime;
import com.attendance.www.hr.entitys.PunchTimeExample;
import com.attendance.www.hr.entitys.Role;
import com.attendance.www.hr.entitys.RoleDepartment;
import com.attendance.www.hr.entitys.RoleDepartmentExample;
import com.attendance.www.hr.entitys.SchedulDayExample;
import com.attendance.www.hr.entitys.SchedulDayKey;
import com.attendance.www.hr.entitys.SchedulWeek;
import com.attendance.www.hr.entitys.SchedulWeekExample;
import com.attendance.www.hr.exception.ResultFaultException;
import com.attendance.www.hr.service.IApprovalService;
import com.attendance.www.hr.service.ISchedulWeekService;
import com.attendance.www.hr.utils.FactorialUtils;
import com.attendance.www.hr.utils.TimeUtils;
import com.attendance.www.hr.utils.ToolUtils;

@Service
public class SchedulWeekServiceImpl implements ISchedulWeekService {

	@Resource
	private SchedulWeekMapper schedulWeekDao;
	@Resource
	private SchedulWeekExtMapper schedulWeekExtDao;
	@Resource
	private SchedulDayMapper schedulDayDao;
	@Resource
	private HolidayMapper holidayDao;
	@Resource
	private EmployeeSchedulMapper employeeSchedulDao;
	@Resource
	private EmployeeMapper employeeDao;
	@Resource
	private IApprovalService approvalService;
	@Resource
	private PunchTimeMapper punchTimeDao;
	@Resource
	private AttachmentMapper attachmentDao;
	@Resource
	private EmployeeExtMapper employeeExtDao;
	@Resource
	private ShiftPermissionExtMapper shiftPermissionExtDao;
	@Resource
	private EmployeeRoleMapper employeeRoleDao;
	@Resource
	private RoleMapper roleDao;
	@Resource
	private DepartmentMapper departmentDao;
	@Resource
	private RoleDepartmentMapper roleDepartmentDao;
	@Resource
	private EmployeeSchedulExtMapper employeeSchedulExtDao;

	/**
	 * 新增
	 * 
	 * @param schedulWeekBean
	 * @param type            true 页面 false 导入
	 * @return
	 */
	@Override
	public boolean saveSchedulWeek(SchedulWeekBean schedulWeekBean, boolean type) {
		// 保存状态 0 失败 1 成功
		int record;
		// 班次类型
		int swType = schedulWeekBean.getSwType();
		// 法定节假日
		Integer isHoliday = schedulWeekBean.getIsHoliday();
		// 班次开始日期
		Date fromDate = schedulWeekBean.getFromDate();
		// 班次结束日期
		Date thruDate = schedulWeekBean.getThruDate();
		// 员工ID集合，用于重计算使用
		List<Integer> resetEmployeeIdList = new ArrayList<Integer>();

		// 班次表
		SchedulWeek schedulWeek = new SchedulWeek();
		schedulWeek.setSwName(schedulWeekBean.getSwName());
		schedulWeek.setSwType(swType);
		schedulWeek.setFromDate(fromDate);
		schedulWeek.setThruDate(thruDate);
		schedulWeek.setIsHoliday(isHoliday);

		// 验证班次名称
		if (this.getSchedulWeekValidate(schedulWeekBean)) {
			throw new ResultFaultException("5_00001");
		}

		// 页面新增验证员工已分配班次
		if (type) {
			// 创建错误信息列表
			List<String> errorMsgList = new ArrayList<String>();
			// 固定班次获取员工号
			List<Integer> employeeIdsList = new ArrayList<Integer>();
			if (schedulWeekBean.getEmployeeIdList() != null) {
				employeeIdsList.addAll(schedulWeekBean.getEmployeeIdList());
			}
			// 无规律班次
			for (EmployeePunchTimeBean employeePunchTimeBean : schedulWeekBean.getEmployeePunchTimeList()) {
				if (employeePunchTimeBean.getEmployeeList() != null) {
					List<Integer> employeeIdList = employeePunchTimeBean.getEmployeeList().stream()
							.map(EmployeeBean::getEmployeeId).collect(Collectors.toList());
					employeeIdsList.addAll(employeeIdList);
				}
			}
			// 过滤重复数据
			employeeIdsList = employeeIdsList.stream().distinct().collect(Collectors.toList());
			// 查询员工
			EmployeeExample employeeExample = new EmployeeExample();
			employeeExample.createCriteria().andEmployeeIdIn(employeeIdsList);
			List<Employee> employeeList = employeeDao.selectByExample(employeeExample);
			// 查询员工班次
			EmployeeSchedulExample esExample = new EmployeeSchedulExample();
			com.attendance.www.hr.entitys.EmployeeSchedulExample.Criteria employeeSchedulCriteria = esExample
					.createCriteria();
			employeeSchedulCriteria.andEmployeeIdIn(employeeIdsList);
			employeeSchedulCriteria.andSwIdNotEqualTo(1);
			if (schedulWeekBean.getSwId() != null) {
				employeeSchedulCriteria.andSwIdNotEqualTo(schedulWeekBean.getSwId());
			}
			List<EmployeeSchedul> employeeSchedulList = employeeSchedulDao.selectByExample(esExample);
			// 获取
			List<Integer> swIdList = employeeSchedulList.stream().map(EmployeeSchedul::getSwId)
					.collect(Collectors.toList());
			
			List<SchedulWeek> swList = new ArrayList<SchedulWeek>();
			if (swIdList.size() > 0) {
				// 查询班次
				SchedulWeekExample schedulWeekExample = new SchedulWeekExample();
				schedulWeekExample.createCriteria().andSwIdIn(swIdList);
				swList = schedulWeekDao.selectByExample(schedulWeekExample);
			}

			// 固定班次
			if (swType == 1) {
				if (employeeSchedulList.size() > 0) {
					String lastCdYearMonth = null;
					// 控制循环用的
					Date curDate = DateUtils.addDays(new Date(schedulWeekBean.getFromDate().getTime()), -1);
					while (curDate.compareTo(schedulWeekBean.getThruDate()) < 0) {
						curDate = DateUtils.addDays(curDate, 1);
						String cdYearMonth = ToolUtils.dateToYearMonthStr(curDate);
						if (!cdYearMonth.equals(lastCdYearMonth)) {
							lastCdYearMonth = cdYearMonth;
						} else {
							continue;
						}
						StringBuilder stringBuilder = new StringBuilder();
						// 获取年月日
						for (Integer employeeId : employeeIdsList) {
							// 获取员工号
							List<Employee> emList = employeeList.stream()
									.filter(s -> s.getEmployeeId().equals(employeeId)).collect(Collectors.toList());
							// 过滤人员
							List<EmployeeSchedul> esList = employeeSchedulList.stream()
									.filter(s -> s.getEmployeeId().equals(employeeId)).collect(Collectors.toList());
							// 过滤年月
							List<EmployeeSchedul> esDayList = esList.stream()
									.filter(s -> ToolUtils.dateToYearMonthStr(s.getFromDate()).equals(cdYearMonth))
									.collect(Collectors.toList());
							if (esDayList.size() > 0) {
								// 获取班次名称
								List<SchedulWeek> swNameList = swList.stream()
										.filter(s -> s.getSwId().equals(esDayList.get(0).getSwId()))
										.collect(Collectors.toList());
								stringBuilder.append("日期(" + cdYearMonth + ")-员工号(" + emList.get(0).getEmployeeNo()
										+ ")已存在班次(" + swNameList.get(0).getSwName() + "),");
							}
						}
						if (stringBuilder.length() > 0) {
							errorMsgList.add(stringBuilder.toString());
						}
					}
				}
			} else {
				// 无规律班次
				for (EmployeePunchTimeBean employeePunchTimeBean : schedulWeekBean.getEmployeePunchTimeList()) {
					StringBuilder stringBuilder = new StringBuilder();
					// 状态为选中
					if (employeePunchTimeBean.isCheckbox()) {
						// 获取人员集合
						List<EmployeeBean> employeeBeanList = employeePunchTimeBean.getEmployeeList();
						// 循环添加班次和人员关系
						for (EmployeeBean employeeBean : employeeBeanList) {
							// 获取员工号
							List<Employee> emList = employeeList.stream()
									.filter(s -> s.getEmployeeId().equals(employeeBean.getEmployeeId()))
									.collect(Collectors.toList());
							// 过滤人员
							List<EmployeeSchedul> esList = employeeSchedulList.stream()
									.filter(s -> s.getEmployeeId().equals(employeeBean.getEmployeeId()))
									.collect(Collectors.toList());
							// 过滤日期
							List<EmployeeSchedul> esDayList = esList.stream()
									.filter(s -> s.getFromDate().equals(employeePunchTimeBean.getDate()))
									.collect(Collectors.toList());
							if (esDayList.size() > 0) {
								// 获取班次名称
								List<SchedulWeek> swNameList = swList.stream()
										.filter(s -> s.getSwId().equals(esDayList.get(0).getSwId()))
										.collect(Collectors.toList());
								stringBuilder.append("日期(" + ToolUtils.dateToStr(employeePunchTimeBean.getDate())
										+ ")-员工号(" + emList.get(0).getEmployeeNo() + ")已存在班次("
										+ swNameList.get(0).getSwName() + "),");
							}
						}
					}
					if (stringBuilder.length() > 0) {
						errorMsgList.add(stringBuilder.toString());
					}
				}
			}
			if (errorMsgList.size() > 0) {
				throw new ResultFaultException("5_00011", errorMsgList);
			}
		}

		// swType 为1 周班次
		if (swType == 1) {
			// 获取一周天数是否选中 1 选中 0 为选中
			int week0 = schedulWeekBean.getSwSunday();
			int week1 = schedulWeekBean.getSwMonday();
			int week2 = schedulWeekBean.getSwTuesday();
			int week3 = schedulWeekBean.getSwWednesday();
			int week4 = schedulWeekBean.getSwThursday();
			int week5 = schedulWeekBean.getSwFriday();
			int week6 = schedulWeekBean.getSwSaturday();
			schedulWeek.setSwMonday(week1);
			schedulWeek.setSwTuesday(week2);
			schedulWeek.setSwWednesday(week3);
			schedulWeek.setSwThursday(week4);
			schedulWeek.setSwFriday(week5);
			schedulWeek.setSwSaturday(week6);
			schedulWeek.setSwSunday(week0);

			// 保存班次
			record = schedulWeekDao.insertSelective(schedulWeek);
			if (record <= 0) {
				return false;
			}
			// 获取保存班次ID
			Integer swId = schedulWeek.getSwId();
			List<Boolean> weekBooleanList = new ArrayList<>();
			// 保存班次日期表数据
			if (week0 == 1) {// 星期日
				weekBooleanList.add(true);
			} else {
				weekBooleanList.add(false);
			}
			if (week1 == 1) {
				weekBooleanList.add(true);
			} else {
				weekBooleanList.add(false);
			}
			if (week2 == 1) {
				weekBooleanList.add(true);
			} else {
				weekBooleanList.add(false);
			}
			if (week3 == 1) {
				weekBooleanList.add(true);
			} else {
				weekBooleanList.add(false);
			}
			if (week4 == 1) {
				weekBooleanList.add(true);
			} else {
				weekBooleanList.add(false);
			}
			if (week5 == 1) {
				weekBooleanList.add(true);
			} else {
				weekBooleanList.add(false);
			}
			if (week6 == 1) {
				weekBooleanList.add(true);
			} else {
				weekBooleanList.add(false);
			}

			// 星期计算
			Calendar calWeek = Calendar.getInstance();
			calWeek.setTime(fromDate);
			int dayForWeek = calWeek.get(Calendar.DAY_OF_WEEK) - 1;// 星期日是
			// 两个日期循环
			Long startTime = fromDate.getTime();
			Long endTime = thruDate.getTime();
			Long oneDay = 1000 * 60 * 60 * 24l;
			// 保存添加班次日期表数据
			List<SchedulDayKey> schedulDayKeyList = new ArrayList<SchedulDayKey>();
			while (startTime <= endTime) {
				int index = dayForWeek % 7;// 循环下标的布尔值
				Date sdDate = new Date(startTime);
				if (weekBooleanList.get(index)) {
					// 班次日表
					SchedulDayKey schedulDayKey = new SchedulDayKey();
					schedulDayKey.setSwId(swId);
					schedulDayKey.setSdDate(sdDate);
					record = schedulDayDao.insert(schedulDayKey);
					schedulDayKeyList.add(schedulDayKey);
					if (record <= 0) {
						return false;
					}
				}
				dayForWeek++;
				startTime += oneDay;
			}

			// 法定节假日
			if (schedulWeekBean.getIsHoliday() == 1) {

				// 获取年
				Integer holidayYear = calWeek.get(Calendar.YEAR);
				// 查询某年的节假日
				HolidayExample holidayExample = new HolidayExample();
				holidayExample.createCriteria().andHolidayYearEqualTo(holidayYear).andHolidayDateBetween(fromDate,
						thruDate);
				List<Holiday> holidayList = holidayDao.selectByExample(holidayExample);
				for (Holiday holiday : holidayList) {
					SchedulDayKey schedulDayKey = new SchedulDayKey();
					schedulDayKey.setSwId(swId);
					// 班次日表
					schedulDayKey.setSdDate(holiday.getHolidayDate());
					if (holiday.getIsToWork() == 1) {
						// 查询是否存在，不存在时添加数据
						List<SchedulDayKey> sdList = schedulDayKeyList.stream()
								.filter(s -> s.getSdDate().equals(schedulDayKey.getSdDate()))
								.collect(Collectors.toList());
						if (sdList.size() <= 0) {
							// 添加
							schedulDayDao.insertSelective(schedulDayKey);
						}
					} else {
						// 删除
						schedulDayDao.deleteByPrimaryKey(schedulDayKey);
					}
				}
			}

			// 添加班次和人员关系表
			List<Integer> employeeIdList = schedulWeekBean.getEmployeeIdList();
			// 添加重计算员工ID
			resetEmployeeIdList.addAll(employeeIdList);
			if (employeeIdList.size() > 0) {
				Calendar calendar = Calendar.getInstance();
				calendar.setTime(schedulWeekBean.getFromDate());
				calendar.add(Calendar.DATE, -1);
				Date thruDateFront = calendar.getTime();

				// 更新有交集的排班,设置人员上个排班结束时间,为本次排班的开始日期的前一天,
				EmployeeSchedulExample employeeSchedulExample = new EmployeeSchedulExample();
				employeeSchedulExample.createCriteria().andFromDateLessThanOrEqualTo(thruDate)
						.andThruDateGreaterThanOrEqualTo(fromDate).andEmployeeIdIn(schedulWeekBean.getEmployeeIdList())
						.andSwIdNotEqualTo(1);
				// 修改班次结束日期
				EmployeeSchedul employeeSchedul = new EmployeeSchedul();
				employeeSchedul.setThruDate(thruDateFront);
				employeeSchedulDao.updateByExampleSelective(employeeSchedul, employeeSchedulExample);

				// 循环添加班次人员关系数
				for (Integer employeeId : employeeIdList) {
					/*
					 * // 处理员工和默认班车结束日期关系 employeeSchedulExample=new EmployeeSchedulExample();
					 * employeeSchedulExample.createCriteria().andEmployeeIdEqualTo(employeeId)
					 * .andSwIdEqualTo(1); List<EmployeeSchedul>
					 * employeeSchedulList=employeeSchedulDao.selectByExample(employeeSchedulExample
					 * ); if(employeeSchedulList.size()>0) { EmployeeSchedul
					 * es=employeeSchedulList.get(0); Date td=null; // 查询员工班次是否存在历史
					 * List<SchedulWeekBean>
					 * swbList=schedulWeekExtDao.getSchedulWeekEmployeeUpListByEmployeeId(employeeId
					 * ); if(swbList.size()>0) { td=swbList.get(0).getFromDate(); }else {
					 * td=schedulWeekBean.getFromDate(); } // 减一个月 td=TimeUtils.getMinusMonth(td);
					 * // 获取月最后一天 td=TimeUtils.getLastDayOfMonth(td); es.setThruDate(td);
					 * employeeSchedulDao.updateByExampleSelective(es, employeeSchedulExample); }
					 */

					employeeSchedul = new EmployeeSchedul();
					employeeSchedul.setSwId(swId);
					employeeSchedul.setEmployeeId(employeeId);
					employeeSchedul.setPunchTimeId(schedulWeekBean.getPunchTimeId());
					employeeSchedul.setFromDate(schedulWeekBean.getFromDate());
					employeeSchedul.setThruDate(schedulWeekBean.getThruDate());
					record = employeeSchedulDao.insertSelective(employeeSchedul);
					if (record <= 0) {
						return false;
					}
				}
			}
		} else if (swType == 2) {
			// 无规律班次
			record = schedulWeekDao.insertSelective(schedulWeek);
			if (record <= 0) {
				return false;
			}
			// 获取保存班次ID
			Integer swId = schedulWeek.getSwId();
			// 保存添加班次日期表数据
			List<SchedulDayKey> schedulDayKeyList = new ArrayList<SchedulDayKey>();
			// 获取无规律班次集合
			List<EmployeePunchTimeBean> employeePunchTimeBeanList = schedulWeekBean.getEmployeePunchTimeList();
			// 循环处理保存数据
			for (EmployeePunchTimeBean employeePunchTimeBean : employeePunchTimeBeanList) {
				// 状态为选中
				if (employeePunchTimeBean.isCheckbox()) {
					EmployeeSchedul employeeSchedul = new EmployeeSchedul();
					employeeSchedul.setSwId(swId);
					employeeSchedul.setPunchTimeId(employeePunchTimeBean.getPunchTimeId());
					employeeSchedul.setFromDate(employeePunchTimeBean.getDate());
					employeeSchedul.setThruDate(employeePunchTimeBean.getDate());

					// 添加班次天
					SchedulDayKey schedulDayKey = new SchedulDayKey();
					schedulDayKey.setSwId(swId);
					schedulDayKey.setSdDate(employeePunchTimeBean.getDate());
					schedulDayDao.insert(schedulDayKey);
					schedulDayKeyList.add(schedulDayKey);

					// 获取人员集合
					List<EmployeeBean> employeeBeanList = employeePunchTimeBean.getEmployeeList();
					// 循环添加班次和人员关系
					for (EmployeeBean employeeBean : employeeBeanList) {
						resetEmployeeIdList.add(employeeBean.getEmployeeId());

						// 删除日期重复的班次人员关系
						EmployeeSchedulExample employeeSchedulExample = new EmployeeSchedulExample();
						employeeSchedulExample.createCriteria().andEmployeeIdEqualTo(employeeBean.getEmployeeId())
								.andFromDateEqualTo(employeeSchedul.getFromDate())
								.andThruDateEqualTo(employeeSchedul.getThruDate());
						employeeSchedulDao.deleteByExample(employeeSchedulExample);

						// 处理员工和默认班车结束日期关系
						/*
						 * employeeSchedulExample=new EmployeeSchedulExample();
						 * employeeSchedulExample.createCriteria().andEmployeeIdEqualTo(employeeBean.
						 * getEmployeeId()) .andSwIdEqualTo(1); List<EmployeeSchedul>
						 * employeeSchedulList=employeeSchedulDao.selectByExample(employeeSchedulExample
						 * ); if(employeeSchedulList.size()>0) { EmployeeSchedul
						 * es=employeeSchedulList.get(0); Date td=null; // 查询员工班次是否存在历史
						 * List<SchedulWeekBean>
						 * swbList=schedulWeekExtDao.getSchedulWeekEmployeeUpListByEmployeeId(
						 * employeeBean.getEmployeeId()); if(swbList.size()>0) {
						 * td=swbList.get(0).getFromDate(); }else { td=employeeSchedul.getFromDate(); }
						 * // 减一个月 td=TimeUtils.getMinusMonth(td); // 获取月最后一天
						 * td=TimeUtils.getLastDayOfMonth(td); // 判断日期大于默认班车结束日期 //es.setThruDate(td);
						 * employeeSchedulDao.updateByExampleSelective(es, employeeSchedulExample); }
						 */

						// 设置人员ID并保存
						employeeSchedul.setEmployeeId(employeeBean.getEmployeeId());
						record = employeeSchedulDao.insertSelective(employeeSchedul);
						if (record <= 0) {
							return false;
						}
					}
				}
			}

			// 法定节假日
			if (schedulWeekBean.getIsHoliday() == 1) {
				// 获取年
				Integer holidayYear = schedulWeekBean.getYear();
				// 查询某年的节假日
				HolidayExample holidayExample = new HolidayExample();
				holidayExample.createCriteria().andHolidayYearEqualTo(holidayYear).andHolidayDateBetween(fromDate,
						thruDate);
				List<Holiday> holidayList = holidayDao.selectByExample(holidayExample);
				for (Holiday holiday : holidayList) {
					if (holiday.getIsToWork() == 0) {
						// 班次日表
						SchedulDayKey schedulDayKey = new SchedulDayKey();
						schedulDayKey.setSwId(swId);
						schedulDayKey.setSdDate(holiday.getHolidayDate());
						// 删除
						schedulDayDao.deleteByPrimaryKey(schedulDayKey);
						// 删除员工和班次
						EmployeeSchedulExample employeeSchedulExample = new EmployeeSchedulExample();
						employeeSchedulExample.createCriteria().andSwIdEqualTo(swId)
								.andFromDateEqualTo(holiday.getHolidayDate())
								.andThruDateEqualTo(holiday.getHolidayDate());
						employeeSchedulDao.deleteByExample(employeeSchedulExample);
					}
				}
			}

			// 处理是否有串休
			List<EmployeePunchTimeBean> employeePunchTimeList = schedulWeekBean.getEmployeePunchTimeList();
			for (int i = 0; i < employeePunchTimeList.size(); i++) {
				EmployeePunchTimeBean employeePunchTimeBean = employeePunchTimeList.get(i);
				// 开始串休人班次
				Date date = employeePunchTimeBean.getDate();
				Integer employeeId = employeePunchTimeBean.getEmployeeId();
				// 结束日期和员工ID
				Date dateRest = employeePunchTimeBean.getDateRest();
				Integer employeeIdRest = employeePunchTimeBean.getEmployeeIdRest();
				if (date != null && employeeId != null && dateRest != null && employeeIdRest != null) {
					// 修改开始串休员工
					EmployeeSchedul employeeSchedul = new EmployeeSchedul();
					employeeSchedul.setEmployeeId(employeeIdRest);

					EmployeeSchedulExample employeeSchedulExample = new EmployeeSchedulExample();
					employeeSchedulExample.createCriteria().andSwIdEqualTo(swId).andEmployeeIdEqualTo(employeeId)
							.andFromDateEqualTo(date).andThruDateEqualTo(date);
					employeeSchedulDao.updateByExampleSelective(employeeSchedul, employeeSchedulExample);

					// 修改结束串休员工
					employeeSchedul = new EmployeeSchedul();
					employeeSchedul.setEmployeeId(employeeId);

					employeeSchedulExample = new EmployeeSchedulExample();
					employeeSchedulExample.createCriteria().andSwIdEqualTo(swId).andEmployeeIdEqualTo(employeeIdRest)
							.andFromDateEqualTo(dateRest).andThruDateEqualTo(dateRest);
					employeeSchedulDao.updateByExampleSelective(employeeSchedul, employeeSchedulExample);
				}
			}
		}

		// 重计算
		Date startDate = schedulWeek.getFromDate();
		Date endDate = schedulWeek.getThruDate();
		// Collectors.toList方法是获取list类型的收集器 distinct方法进行去重 collect进行转换
		List<Integer> employeeIdList = resetEmployeeIdList.stream().distinct().collect(Collectors.toList());
		approvalService.resetAttendance(startDate, endDate, employeeIdList);

		return true;
	}

	/**
	 * 删除
	 */
	@Override
	public boolean deleteSchedulWeek(Integer swId) {
		List<Integer> employeeIdList = schedulWeekExtDao.getEmployeeListBySwId(swId);
		// 物理删除排班表 t_schedul_week
		SchedulWeek schedulWeek = schedulWeekDao.selectByPrimaryKey(swId);

		int record = schedulWeekDao.deleteByPrimaryKey(swId);
		if (record <= 0) {
			return false;
		}

		// 删除班次天表 t_schedul_day信息
		SchedulDayExample schedulDayExample = new SchedulDayExample();
		schedulDayExample.createCriteria().andSwIdEqualTo(swId);
		schedulDayDao.deleteByExample(schedulDayExample);

		// 删除人员排班表 t_employee_schedul
		if (employeeIdList.size() > 0) {
			EmployeeSchedulExample example = new EmployeeSchedulExample();
			example.createCriteria().andSwIdEqualTo(swId);
			employeeSchedulDao.deleteByExample(example);
		}

		// 重计算
		Date startDate = schedulWeek.getFromDate();
		Date endDate = schedulWeek.getThruDate();
		Date curDate = new Date();
		if (startDate.after(curDate)) {
			startDate = curDate;
		}
		if (endDate.after(curDate)) {
			endDate = curDate;
		}
		approvalService.resetAttendance(startDate, endDate, employeeIdList);
		return true;
	}

	/**
	 * 修改
	 */
	@Override
	public boolean updateSchedulWeek(SchedulWeekBean schedulWeekBean) {
		Integer swId = schedulWeekBean.getSwId();
		List<Integer> employeeIdList = schedulWeekExtDao.getEmployeeListBySwId(swId);
		// 物理删除排班表 t_schedul_week
		schedulWeekDao.deleteByPrimaryKey(swId);

		// 删除班次天表 t_schedul_day信息
		SchedulDayExample schedulDayExample = new SchedulDayExample();
		schedulDayExample.createCriteria().andSwIdEqualTo(swId);
		schedulDayDao.deleteByExample(schedulDayExample);

		// 删除人员排班表 t_employee_schedul
		if (employeeIdList.size() > 0) {
			EmployeeSchedulExample example = new EmployeeSchedulExample();
			example.createCriteria().andSwIdEqualTo(swId);
			employeeSchedulDao.deleteByExample(example);
		}

		return this.saveSchedulWeek(schedulWeekBean, true);
	}

	/**
	 * 批量修改考勤时间
	 * 
	 * @param schedulWeekBean
	 * @return
	 */
	@Override
	public boolean batchPunchTime(SchedulWeekBean schedulWeekBean) {
		// 获取班次集合
		SchedulWeekExample schedulWeekExample = new SchedulWeekExample();
		schedulWeekExample.createCriteria().andSwIdIn(schedulWeekBean.getSwIdList());
		List<SchedulWeek> schedulWeekList = schedulWeekDao.selectByExample(schedulWeekExample);

		// 获取员工和班次关键
		EmployeeSchedulExample employeeSchedulExample = new EmployeeSchedulExample();
		employeeSchedulExample.createCriteria().andSwIdIn(schedulWeekBean.getSwIdList());
		List<EmployeeSchedul> employeeSchedulList = employeeSchedulDao.selectByExample(employeeSchedulExample);

		// 循环班次集合
		for (int i = 0; i < schedulWeekBean.getSwIdList().size(); i++) {
			Integer swId = schedulWeekBean.getSwIdList().get(i);
			// 设置查询条件
			employeeSchedulExample = new EmployeeSchedulExample();
			employeeSchedulExample.createCriteria().andSwIdEqualTo(swId);
			// 设置更改字段
			EmployeeSchedul employeeSchedul = new EmployeeSchedul();
			employeeSchedul.setPunchTimeId(schedulWeekBean.getPunchTimeId());
			int record = employeeSchedulDao.updateByExampleSelective(employeeSchedul, employeeSchedulExample);
			if (record <= 0) {
				return false;
			}
		}
		// 循环调用重计算考勤
		for (int j = 0; j < schedulWeekList.size(); j++) {
			SchedulWeek schedulWeek = schedulWeekList.get(j);
			// 重计算
			Date startDate = schedulWeek.getFromDate();
			Date endDate = schedulWeek.getThruDate();
			// Collectors.toList方法是获取list类型的收集器 distinct方法进行去重 collect进行转换
			List<Integer> employeeIdList = employeeSchedulList.stream().map(EmployeeSchedul::getEmployeeId)
					.collect(Collectors.toList());
			approvalService.resetAttendance(startDate, endDate, employeeIdList);
		}
		return true;
	}

	/**
	 * 获取班次分页查询
	 * 
	 * @param schedulWeekBean
	 * @param startNum
	 * @param pageCount
	 * @param employeeId
	 * @return
	 */
	@Override
	public SchedulWeekPageBean getSchedulWeekList(SchedulWeekBean schedulWeekBean, Integer startNum, Integer pageCount,
			Integer employeeId) {
		if (schedulWeekBean.getEmployeeList() != null && schedulWeekBean.getEmployeeList().size() > 0) {
			EmployeeBean employeeBean = new EmployeeBean();
			employeeBean.setEmployeeList(schedulWeekBean.getEmployeeList());
			List<EmployeeBean> employeeBeanList = employeeExtDao.getEmployeePageList(employeeBean, null, null);
			if (employeeBeanList.size() > 0) {
				List<Integer> employeeIdList = employeeBeanList.stream().map(EmployeeBean::getEmployeeId)
						.collect(Collectors.toList());
				schedulWeekBean.setEmployeeIdList(employeeIdList);
			} else {
				List<Integer> employeeIdList = new ArrayList<Integer>();
				employeeIdList.add(0);
				schedulWeekBean.setEmployeeIdList(employeeIdList);
			}
		}

		// 根据登录人员ID，获取班次权限管理部门集合
		if (employeeId != null) {
			List<Integer> departmentIdList = shiftPermissionExtDao.getShiftPermissionDepartmentIdList(employeeId);
			if (departmentIdList != null && departmentIdList.size() > 0) {
				schedulWeekBean.setDepartmentIdList(departmentIdList);
			}
		}
		List<SchedulWeekBean> schedulWeekBeanList = schedulWeekExtDao.getSchedulWeekList(schedulWeekBean, startNum,
				pageCount);
		Integer pageTotal = schedulWeekExtDao.getSchedulWeekTotal(schedulWeekBean);
		for (int i = 0; i < schedulWeekBeanList.size(); i++) {
			// 查询班次人员数量
			Integer employeeSum = schedulWeekExtDao.getEmployeeIdCountBySwId(schedulWeekBeanList.get(i).getSwId());
			schedulWeekBeanList.get(i).setEmployeeSum(employeeSum);

			if (schedulWeekBeanList.get(i).getSwType() == 1) {
				// 查询班次打卡时间数量
				List<Integer> punchTimeIdList = schedulWeekExtDao
						.getPunchTimeIdListBySwId(schedulWeekBeanList.get(i).getSwId());
				if (punchTimeIdList.size() <= 1) {
					PunchTime punchTime = punchTimeDao.selectByPrimaryKey(punchTimeIdList.get(0));
					if (punchTime != null) {
						schedulWeekBeanList.get(i).setPunchTimeId(punchTime.getPunchTimeId());
						schedulWeekBeanList.get(i).setStartFromTime(punchTime.getStartFromTime());
						schedulWeekBeanList.get(i).setStartToTime(punchTime.getStartToTime());
						schedulWeekBeanList.get(i).setStartInterval(punchTime.getStartInterval());
						schedulWeekBeanList.get(i).setEndFromTime(punchTime.getEndFromTime());
						schedulWeekBeanList.get(i).setEndToTime(punchTime.getEndToTime());
						schedulWeekBeanList.get(i).setEndInterval(punchTime.getEndInterval());
					}
				}
			} else {
				List<EmployeeBean> employeeBeanList = employeeSchedulExtDao
						.selectPunchTimeIdListBySwId(schedulWeekBeanList.get(i).getSwId());
				if (employeeBeanList.size() == 1) {
					EmployeeBean employeeBean = employeeBeanList.get(0);
					schedulWeekBeanList.get(i).setPunchTimeId(employeeBean.getPunchTimeId());
					schedulWeekBeanList.get(i).setStartFromTime(employeeBean.getStartFromTime());
					schedulWeekBeanList.get(i).setStartToTime(employeeBean.getStartToTime());
					schedulWeekBeanList.get(i).setStartInterval(employeeBean.getStartInterval());
					schedulWeekBeanList.get(i).setEndFromTime(employeeBean.getEndFromTime());
					schedulWeekBeanList.get(i).setEndToTime(employeeBean.getEndToTime());
					schedulWeekBeanList.get(i).setEndInterval(employeeBean.getEndInterval());
				}
			}
		}

		SchedulWeekPageBean schedulWeekPageBean = new SchedulWeekPageBean();
		schedulWeekPageBean.setSchedulWeekBeanList(schedulWeekBeanList);
		schedulWeekPageBean.setPageTotal(pageTotal);
		return schedulWeekPageBean;
	}

	/**
	 * 查询班次by班次ID
	 * 
	 * @param swId
	 * @return
	 */
	@Override
	public SchedulWeekBean getSchedulWeekBySwId(Integer swId) {
		SchedulWeekBean schedulWeekBean = new SchedulWeekBean();
		SchedulWeek schedulWeek = schedulWeekDao.selectByPrimaryKey(swId);
		int swType = schedulWeek.getSwType();
		schedulWeekBean.setSwId(swId);
		schedulWeekBean.setSwName(schedulWeek.getSwName());
		schedulWeekBean.setFromDate(schedulWeek.getFromDate());
		schedulWeekBean.setThruDate(schedulWeek.getThruDate());
		schedulWeekBean.setSwType(swType);
		if (swType == 1) {// 周班次
			schedulWeekBean.setSwMonday(schedulWeek.getSwMonday());
			schedulWeekBean.setSwTuesday(schedulWeek.getSwTuesday());
			schedulWeekBean.setSwWednesday(schedulWeek.getSwWednesday());
			schedulWeekBean.setSwThursday(schedulWeek.getSwThursday());
			schedulWeekBean.setSwFriday(schedulWeek.getSwFriday());
			schedulWeekBean.setSwSaturday(schedulWeek.getSwSaturday());
			schedulWeekBean.setSwSunday(schedulWeek.getSwSunday());
			schedulWeekBean.setIsDefault(schedulWeek.getIsDefault());
			schedulWeekBean.setIsHoliday(schedulWeek.getIsHoliday());
			// 获取班次人员集合
			List<Integer> employeeList = schedulWeekExtDao.getEmployeeListBySwId(swId);
			schedulWeekBean.setEmployeeIdList(employeeList);
		}
		if (swType == 2) {
			// 获取班次天数
			SchedulDayExample example = new SchedulDayExample();
			example.createCriteria().andSwIdEqualTo(swId);
			List<SchedulDayKey> schedulDayKeyList = schedulDayDao.selectByExample(example);
			List<Date> dateList = new ArrayList<>();
			for (SchedulDayKey schedulDayKey : schedulDayKeyList) {
				dateList.add(schedulDayKey.getSdDate());
			}
			schedulWeekBean.setDateList(dateList);

			// 获取班次人员关系
			EmployeeSchedulExample employeeSchedulExample = new EmployeeSchedulExample();
			employeeSchedulExample.createCriteria().andSwIdEqualTo(swId);
			List<EmployeeSchedul> employeeSchedulList = employeeSchedulDao.selectByExample(employeeSchedulExample);

			// 获取班次
			List<SchedulWeekBean> punchTimeIdDateList = schedulWeekExtDao.getDatePunchTimeIdListBySwId(swId);
			List<EmployeePunchTimeBean> employeePunchTimeList = new ArrayList<EmployeePunchTimeBean>();
			if (punchTimeIdDateList.size() > 0) {
				for (int i = 0; i < punchTimeIdDateList.size(); i++) {
					EmployeePunchTimeBean employeePunchTimeBean = new EmployeePunchTimeBean();
					employeePunchTimeBean.setDate(punchTimeIdDateList.get(i).getFromDate());
					employeePunchTimeBean.setPunchTimeId(punchTimeIdDateList.get(i).getPunchTimeId());
					employeePunchTimeBean.setCheckbox(true);
					List<EmployeeSchedul> esList = employeeSchedulList.stream()
							.filter(s -> s.getFromDate().equals(employeePunchTimeBean.getDate()))
							.collect(Collectors.toList());
					// 添加员工
					List<EmployeeBean> employeeList = new ArrayList<EmployeeBean>();
					for (EmployeeSchedul employeeSchedul : esList) {
						EmployeeBean employeeBean = new EmployeeBean();
						employeeBean.setEmployeeId(employeeSchedul.getEmployeeId());
						employeeBean.setCheckbox(true);
						employeeList.add(employeeBean);
					}
					employeePunchTimeBean.setEmployeeList(employeeList);
					employeePunchTimeList.add(employeePunchTimeBean);
				}
				schedulWeekBean.setEmployeePunchTimeList(employeePunchTimeList);
			}
		}
		return schedulWeekBean;
	}

	/**
	 * 获取班次员工详情
	 * 
	 * @param swId
	 * @return
	 */
	public List<EmployeeBean> getSchedulWeekEmployeeDetailedList(Integer swId) {
		List<EmployeeBean> employeeBeanList = schedulWeekExtDao.getSchedulWeekEmployeeDetailedList(swId);
		// 通过人员ID查对应的roleList，多岗位
		for (EmployeeBean employeeBean : employeeBeanList) {
			EmployeeRoleExample employeeRoleExample = new EmployeeRoleExample();
			employeeRoleExample.createCriteria().andEmployeeIdEqualTo(employeeBean.getEmployeeId());
			employeeRoleExample.setOrderByClause("is_role desc");
			List<EmployeeRole> employeeRoleList = employeeRoleDao.selectByExample(employeeRoleExample);
			List<RoleBean> roleBeanList = new ArrayList<>();
			// 查询岗位信息by Id
			for (EmployeeRole employeeRole : employeeRoleList) {
				// 每个人对应的岗位，循环
				Role role = roleDao.selectByPrimaryKey(employeeRole.getRoleId());

				// 查询岗位对应部门
				RoleDepartmentExample roleDepartmentExample = new RoleDepartmentExample();
				roleDepartmentExample.createCriteria().andRoleIdEqualTo(role.getRoleId());
				List<RoleDepartment> roleDepartmentList = roleDepartmentDao.selectByExample(roleDepartmentExample);
				Department department = null;
				if (roleDepartmentList.size() > 0) {
					// 查岗位对应的部门
					department = departmentDao.selectByPrimaryKey(roleDepartmentList.get(0).getDepartmentId());
				}
				if (role.getIsDisabled() != 1) {
					// 导入岗位bean
					RoleBean roleBean = new RoleBean();
					roleBean.setDescription(role.getDescription());
					roleBean.setParentId(role.getParentId());
					roleBean.setRoleCode(role.getRoleCode());
					roleBean.setRoleId(role.getRoleId());
					roleBean.setRoleLevel(role.getRoleLevel());
					roleBean.setRoleName(role.getRoleName());
					roleBean.setIsRole(employeeRole.getIsRole());
					roleBean.setFromDate(employeeRole.getFromDate());
					roleBean.setThruDate(employeeRole.getThruDate());
					if (department != null) {
						roleBean.setDepartmentName(department.getDepartmentName());
						roleBean.setDepartmentCode(department.getDepartmentCode());
					}
					roleBeanList.add(roleBean);
				}
				employeeBean.setRoleList(roleBeanList);
			}
		}
		return employeeBeanList;
	}

	/**
	 * 根据ID获取班次内员工集合
	 * 
	 * @param request
	 * @return
	 */
	@Override
	public List<SchedulWeekBean> getSchedulWeekEmployeeListBySwId(SchedulWeekBean schedulWeekBean) {
		return schedulWeekExtDao.getSchedulWeekEmployeeListBySwId(schedulWeekBean);
	}

	/**
	 * 验证
	 */
	@Override
	public boolean getSchedulWeekValidate(SchedulWeekBean schedulWeekBean) {
		SchedulWeekExample schedulWeekExample = new SchedulWeekExample();
		SchedulWeekExample.Criteria schedulWeekCriter = schedulWeekExample.createCriteria();
		schedulWeekCriter.andSwNameEqualTo(schedulWeekBean.getSwName());
		schedulWeekCriter.andIsDeleteEqualTo(0);
		// 一.查询班次名称是否重复
		List<SchedulWeek> schedulWeekList = schedulWeekDao.selectByExample(schedulWeekExample);
		if (schedulWeekList.size() > 0) {
			return true;
		}
		return false;
	}

	/**
	 * 删除验证是否存在
	 */
	@Override
	public boolean getDeleteSchedulWeekValidate(String id) {
		SchedulWeek schedulWeek = schedulWeekDao.selectByPrimaryKey(Integer.parseInt(id));
		if (schedulWeek == null) {
			throw new ResultFaultException("0_00012");
		}
		return true;
	}

	/**
	 * 验证是否排班时间有重叠
	 */
	@Override
	public boolean getVerifySchedulWeek(SchedulWeekBean schedulWeekBean) {
		List<Integer> employeeIdList = schedulWeekBean.getEmployeeIdList();
		if (employeeIdList.size() > 0) {
			EmployeeSchedulExample example = new EmployeeSchedulExample();
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(schedulWeekBean.getFromDate());
			calendar.add(Calendar.DATE, -1);
			Date thruDate = calendar.getTime();
			// 原排班的结束日期大于本次排班的开始日期前一日//原排班的开始日期小于本次的结束日期，//且除去本排班swId的//更新，员工ID在list内的，，就是有重叠
			EmployeeSchedulExample.Criteria cri = example.createCriteria();
			cri.andThruDateGreaterThan(thruDate).andEmployeeIdIn(employeeIdList);
			if (schedulWeekBean.getIsDefault() != 1) {
				cri.andFromDateLessThan(schedulWeekBean.getThruDate());
			}
			// 新增没swID，修改有swId
			if (schedulWeekBean.getSwId() != null) {
				cri.andSwIdNotEqualTo(schedulWeekBean.getSwId());
			}
			if (employeeSchedulDao.selectByExample(example).size() > 0) {
				return true;
			}
		}
		return false;
	}

	/**
	 * 新增（自动添加）周班次天数据 只是默认班次
	 */
	@Override
	public boolean saveSchedulDayKeyAuto() {
		Date nowDate = new Date();
		SchedulWeekExample schedulWeekExample = new SchedulWeekExample();
		schedulWeekExample.createCriteria().andIsDefaultEqualTo(1);
		List<SchedulWeek> schedulWeeklist = schedulWeekDao.selectByExample(schedulWeekExample);
		List<Integer> swIdList = new ArrayList<Integer>();
		for (int si = 0; si < schedulWeeklist.size(); si++) {
			swIdList.add(schedulWeeklist.get(si).getSwId());
		}

		// 删除已经生成班车数据
		if (swIdList.size() > 0) {
			// 计算下个月月初和月末时间
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(nowDate);
			// calendar.add(Calendar.MONTH, 1);
			calendar.set(Calendar.DAY_OF_MONTH, 1);
			Date monthStartDate = calendar.getTime();// 月初时间
			calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));

			// 月末
			Calendar ofCalendar = Calendar.getInstance();
			ofCalendar.setTime(nowDate);
			ofCalendar.add(Calendar.MONTH, 6);
			ofCalendar.set(Calendar.DAY_OF_MONTH, 1);
			Date ofMonthStartDate = ofCalendar.getTime();// 月初时间
			ofCalendar.set(Calendar.DAY_OF_MONTH, ofCalendar.getActualMaximum(Calendar.DAY_OF_MONTH));
			Date ofMonthEndDate = ofCalendar.getTime();// 月末时间

			SchedulDayExample schedulDayExample = new SchedulDayExample();
			schedulDayExample.createCriteria().andSwIdIn(swIdList).andSdDateBetween(monthStartDate, ofMonthEndDate);
			int record = schedulDayDao.countByExample(schedulDayExample);
			if (record > 0) {
				schedulDayDao.deleteByExample(schedulDayExample);
			}
		}

		// 六个月版本
		for (int i = 0; i < 7; i++) {
			// 计算下个月月初和月末时间
			Calendar calendar = Calendar.getInstance();
			calendar.setTime(nowDate);
			calendar.add(Calendar.MONTH, i);
			calendar.set(Calendar.DAY_OF_MONTH, 1);
			Date monthStartDate = calendar.getTime();// 月初时间
			calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
			Date monthEndDate = calendar.getTime();// 月末时间
			// 生成班车
			this.setSchedulDay(schedulWeeklist, monthStartDate, monthEndDate);
		}
		return true;
	}

	/**
	 * 生成班车
	 * 
	 * @param schedulWeeklist
	 * @param monthStartDate
	 * @param monthEndDate
	 * @return
	 */
	private void setSchedulDay(List<SchedulWeek> schedulWeeklist, Date monthStartDate, Date monthEndDate) {
		// 循环各个周班次(现在仅有默认班次)
		for (SchedulWeek schedulWeek : schedulWeeklist) {
			int swId = schedulWeek.getSwId();
			int record;
			// 周班次星期几上班与否的list<boolean>
			int week0 = schedulWeek.getSwSunday();
			int week1 = schedulWeek.getSwMonday();
			int week2 = schedulWeek.getSwTuesday();
			int week3 = schedulWeek.getSwWednesday();
			int week4 = schedulWeek.getSwThursday();
			int week5 = schedulWeek.getSwFriday();
			int week6 = schedulWeek.getSwSaturday();

			List<Boolean> weekBooleanList = new ArrayList<>();
			if (week0 == 1) {// 星期日，index=0
				weekBooleanList.add(true);
			} else {
				weekBooleanList.add(false);
			}
			if (week1 == 1) {
				weekBooleanList.add(true);
			} else {
				weekBooleanList.add(false);
			}
			if (week2 == 1) {
				weekBooleanList.add(true);
			} else {
				weekBooleanList.add(false);
			}
			if (week3 == 1) {
				weekBooleanList.add(true);
			} else {
				weekBooleanList.add(false);
			}
			if (week4 == 1) {
				weekBooleanList.add(true);
			} else {
				weekBooleanList.add(false);
			}
			if (week5 == 1) {
				weekBooleanList.add(true);
			} else {
				weekBooleanList.add(false);
			}
			if (week6 == 1) {
				weekBooleanList.add(true);
			} else {
				weekBooleanList.add(false);
			}

			// 星期计算
			Calendar calWeek = Calendar.getInstance();
			calWeek.setTime(monthStartDate);
			int dayForWeek = calWeek.get(Calendar.DAY_OF_WEEK) - 1;// 星期日是0....

			/**
			 * 两个日期循环,自动新增班次天表
			 */
			Long startTime = monthStartDate.getTime();
			Long endTime = monthEndDate.getTime();
			Long oneDay = 1000 * 60 * 60 * 24l;

			SchedulDayKey schedulDayKey = new SchedulDayKey();// 班次天表(双主键)
			schedulDayKey.setSwId(swId);
			while (startTime <= endTime) {
				int index = dayForWeek % 7;// 循环下标的布尔值
				Date sdDate = new Date(startTime);
				if (weekBooleanList.get(index)) {
					schedulDayKey.setSdDate(sdDate);
					SchedulDayExample schedulDayExample = new SchedulDayExample();
					schedulDayExample.createCriteria().andSwIdEqualTo(swId).andSdDateEqualTo(sdDate);
					record = schedulDayDao.countByExample(schedulDayExample);
					if (record <= 0) {
						schedulDayDao.insert(schedulDayKey);
					}
				}
				dayForWeek++;
				startTime += oneDay;
			}

			// 判断is Holiday
			if (schedulWeek.getIsHoliday() == 1) {
				// 查询某年的节假日
				HolidayExample holidayExample = new HolidayExample();
				int year = calWeek.get(Calendar.YEAR);
				holidayExample.createCriteria().andHolidayYearEqualTo(year);
				List<Holiday> holidayList = holidayDao.selectByExample(holidayExample);
				// 删除再添加，两步走
				SchedulDayKey sdKey = new SchedulDayKey();
				sdKey.setSwId(swId);
				for (Holiday holiday : holidayList) {
					Date holidayDate = holiday.getHolidayDate();
					sdKey.setSdDate(holidayDate);
					record = schedulDayDao.deleteByPrimaryKey(sdKey);
					schedulDayKey.setSdDate(holidayDate);
					if (holiday.getIsToWork() == 1) {
						schedulDayDao.insertSelective(schedulDayKey);
					}
				}
			}
		}
	}

	/**
	 * 无规律班次导入
	 * 
	 * @param attachmentId
	 * @param employeeId
	 * @return
	 */
	@Override
	public List<String> schedulWeekImport(Integer attachmentId, Integer employeeId) {
		List<String> successList = new ArrayList<String>();
		// 查询附件表获取路径地址
		Attachment attachment = attachmentDao.selectByPrimaryKey(attachmentId);
		// 设置文件路径
		String pathName = attachment.getUrl().replace(AppConstant.UPLOAD_RESOURCE, AppConstant.SAVE_FILE_REPOSITORY);
		File file = new File(pathName);
		Workbook work = null;
		if (file.exists()) {
			try {
				InputStream inputStream = new FileInputStream(file);
				if (pathName.matches("^.+\\.(?i)(xls)$")) {
					work = new HSSFWorkbook(inputStream);
				} else if (pathName.matches("^.+\\.(?i)(xlsx)$")) {
					work = new XSSFWorkbook(inputStream);
				}
			} catch (Exception ex) {
				throw new ResultFaultException("0_00003");
			}
		} else {
			throw new ResultFaultException("0_00003");
		}
		if (work == null) {
			throw new ResultFaultException("0_00003");
		}

		if (work != null) {
			successList = addSchedulWeek(work, successList, employeeId);
		}
		return successList;
	}

	/**
	 * 导入excel表格，逐行读取操作
	 * 
	 * @param work12
	 * @param successList
	 * @param employeeId
	 * @return
	 */
	private List<String> addSchedulWeek(Workbook work, List<String> successList, Integer employeeId) {
		// 根据登录人员ID，获取班次权限管理部门集合
		EmployeeBean employeeBean = new EmployeeBean();
		if (employeeId != null) {
			List<Integer> departmentIdList = shiftPermissionExtDao.getShiftPermissionDepartmentIdList(employeeId);
			if (departmentIdList != null && departmentIdList.size() > 0) {
				employeeBean.setDepartmentIdStatus(true);
				employeeBean.setDepartmentIdList(departmentIdList);
			}
		}
		List<EmployeeBean> employeeBeanList = employeeExtDao.getEmployeePageList(employeeBean, null, null);

		// 获取考勤时间
		PunchTimeExample ptExample = new PunchTimeExample();
		ptExample.createCriteria().andIsDeleteEqualTo(0);
		List<PunchTime> punchTimeList = punchTimeDao.selectByExample(ptExample);

		// 获取班次
		SchedulWeekExample schedulWeekExample = new SchedulWeekExample();
		schedulWeekExample.createCriteria().andIsDeleteEqualTo(0).andSwTypeEqualTo(2);
		List<SchedulWeek> schedulWeekList = schedulWeekDao.selectByExample(schedulWeekExample);

		// 获取员工和班次关系
		List<Integer> swIdList = schedulWeekList.stream().map(SchedulWeek::getSwId).collect(Collectors.toList());
		EmployeeSchedulExample employeeSchedulExample = new EmployeeSchedulExample();
		employeeSchedulExample.createCriteria().andSwIdIn(swIdList);
		List<EmployeeSchedul> employeeSchedulList = employeeSchedulDao.selectByExample(employeeSchedulExample);

		// 获取工作表的数量
		int sheetNum = work.getNumberOfSheets();
		// 遍历工作表 找出要导入的Excel表
		for (int m = 0; m < sheetNum; m++) {
			Sheet sh = work.getSheetAt(m);
			if (sh.getSheetName().equals("班次信息")) {
				Sheet sheet = work.getSheetAt(m);
				List<String> errorMsgList = new ArrayList<String>();// 创建错误信息列表
				// 排班Bean
				SchedulWeekBean schedulWeekBean = new SchedulWeekBean();
				schedulWeekBean.setSwType(2);
				// 排班日期（上班和休息的），打卡id的List
				List<EmployeePunchTimeBean> employeePunchTimeBeanList = new ArrayList<EmployeePunchTimeBean>();
				// 格式化日期
				SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
				// 单元格
				String cellValue = "";
				// 获取班次标题和获取法定节假日
				Row row = sheet.getRow(0);
				// 班次标题
				if (row.getCell(1) == null || StringUtils.isBlank(row.getCell(1).toString())) {
					errorMsgList.add("班次名称，不能为空。");
				} else {
					schedulWeekBean.setSwName(row.getCell(1).toString());
					// 验证班次名称
					if (this.getSchedulWeekValidate(schedulWeekBean)) {
						errorMsgList.add("班次名称已存在！");
					}
				}

				// 法定节假日
				if (row.getCell(4) == null || StringUtils.isBlank(row.getCell(4).toString())) {
					errorMsgList.add("法定节假日，不能为空。");
				} else {
					// 验证法定节假日格式
					Integer isHoliday = null;
					if (row.getCell(4).toString().equals("是")) {
						isHoliday = 1;
						schedulWeekBean.setIsHoliday(isHoliday);
					} else if (row.getCell(4).toString().equals("否")) {
						isHoliday = 0;
						schedulWeekBean.setIsHoliday(isHoliday);
					} else {
						errorMsgList.add("法定节假日，格式不准确。");
					}
				}
				// 获取班次年份-月份
				row = sheet.getRow(1);
				// 年份
				if (row.getCell(1) == null || StringUtils.isBlank(row.getCell(1).toString())) {
					errorMsgList.add("班次年份，不能为空。");
				} else {
					try {
						if (row.getCell(1).getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
							schedulWeekBean.setYear(new BigDecimal(row.getCell(1).getNumericCellValue()).intValue());
						} else {
							schedulWeekBean.setYear(Integer.parseInt(row.getCell(1).toString()));
						}
					} catch (Exception e) {
						errorMsgList.add("班次年份格式不正确,");
					}
				}

				// 月份
				if (row.getCell(4) == null || StringUtils.isBlank(row.getCell(4).toString())) {
					errorMsgList.add("班次月份，不能为空。");
				} else {
					try {
						if (row.getCell(4).getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
							schedulWeekBean.setMonth(new BigDecimal(row.getCell(4).getNumericCellValue()).intValue());
						} else {
							schedulWeekBean.setMonth(Integer.parseInt(row.getCell(4).toString()));
						}
					} catch (Exception e) {
						errorMsgList.add("班次月份格式不正确,");
					}
				}

				// 循环获取Excel每行的每个单元格
				for (int i = 4; i <= sheet.getLastRowNum() + 1; i++) {
					StringBuilder stringBuilder = new StringBuilder("第" + (i + 1) + "行：");
					row = sheet.getRow(i);
					// 如果一整行为空则忽略此行继续遍历
					if (row == null) {
						continue;
					}
					// 遍历某一行的所有列，如果此行每列都为空则跳过继续下一行
					boolean isNull = true;
					for (int c = 0; c < row.getLastCellNum(); c++) {
						if (row.getCell(c) == null || StringUtils.isBlank(row.getCell(c).toString())) {
							continue;
						} else {
							isNull = false;
						}
					}
					if (isNull) {
						continue;
					}
					// 考勤时间ID
					Integer punchTimeId = null;
					// 员工ID
					Integer employeeIdNo = null;
					// 员工号
					String employeeNo = null;
					// 班次日期
					Date date = null;
					// 考勤时间
					PunchTime punchTime = new PunchTime();
					// 列号
					int columns = 0;
					// 日期
					if (row.getCell(columns) != null && StringUtils.isNotBlank(row.getCell(columns).toString())) {
						// 判断是否为字符串或是日期类型
						try {
							// 判断是否为字符串
							if (row.getCell(columns).getCellType() == HSSFCell.CELL_TYPE_STRING) {
								date = dateFormat.parse(row.getCell(columns).toString());
							}
							// 判断是否为日期
							else if (HSSFDateUtil.isCellDateFormatted(row.getCell(columns))) {
								date = row.getCell(columns).getDateCellValue();
							} else {
								date = ToolUtils.formatData(row.getCell(columns).toString());
							}
						} catch (Exception e) {
							stringBuilder.append("日期格式不正确,");
						}
					} else {
						stringBuilder.append("日期不能为空,");
					}
					columns++;
					// 签到时间
					if (row.getCell(columns) != null && StringUtils.isNotBlank(row.getCell(columns).toString())) {
						// 判断格式是否正确
						cellValue = row.getCell(columns).toString();
						if (row.getCell(columns).getCellType() == HSSFCell.CELL_TYPE_STRING
								&& cellValue.contains("-")) {
							// 08:00-10:00 分隔-
							String[] strCellValue = cellValue.split("-");
							if (strCellValue.length >= 2) {
								punchTime.setStartFromTime(strCellValue[0]);
								punchTime.setStartToTime(strCellValue[1]);
							} else {
								stringBuilder.append("签到时间格式不能正确,");
							}
						} else {
							punchTime.setStartFromTime(cellValue);
							punchTime.setStartToTime(cellValue);
						}
					} else {
						stringBuilder.append("签到时间不能为空,");
					}
					columns++;
					// 末班签退
					if (row.getCell(columns) != null && StringUtils.isNotBlank(row.getCell(columns).toString())) {
						// 判断格式是否正确
						cellValue = row.getCell(columns).toString();
						if (row.getCell(columns).getCellType() == HSSFCell.CELL_TYPE_STRING
								&& cellValue.contains("-")) {
							// 08:00-10:00 分隔-
							String[] strCellValue = cellValue.split("-");
							if (strCellValue.length >= 2) {
								punchTime.setEndFromTime(strCellValue[0]);
								punchTime.setEndToTime(strCellValue[1]);
							}
						} else {
							punchTime.setEndFromTime(cellValue);
							punchTime.setEndToTime(cellValue);
						}

						// 当签到时间和末班签退不为空验证考勤时间是否存在
						if (punchTime.getStartFromTime() != null && punchTime.getStartToTime() != null
								&& punchTime.getEndFromTime() != null && punchTime.getEndToTime() != null) {
							List<PunchTime> ptList = punchTimeList.stream()
									.filter(s -> s.getStartFromTime().equals(punchTime.getStartFromTime())
											&& s.getStartToTime().equals(punchTime.getStartToTime())
											&& s.getEndFromTime().equals(punchTime.getEndFromTime())
											&& s.getEndToTime().equals(punchTime.getEndToTime()))
									.collect(Collectors.toList());
							if (ptList.size() > 0) {
								punchTimeId = ptList.get(0).getPunchTimeId();
							} else {
								stringBuilder.append("考勤时间不存在,");
							}
						}
					} else {
						stringBuilder.append("末班签退不能为空,");
					}
					columns++;
					// 工号号
					if (row.getCell(columns) != null && StringUtils.isNotBlank(row.getCell(columns).toString())) {
						// 判断是否为数字
						if (row.getCell(columns).getCellType() == HSSFCell.CELL_TYPE_NUMERIC) {
							cellValue = new BigDecimal(row.getCell(columns).getNumericCellValue()).intValue() + "";
						} else {
							cellValue = row.getCell(columns).toString();
						}
						if (cellValue.length() <= 4) {
							cellValue = "0" + cellValue;
						}
						final String value = cellValue.toString();
						// 验证员工号是否存在
						List<EmployeeBean> ebList = employeeBeanList.stream()
								.filter(s -> s.getEmployeeNo().equals(value)).collect(Collectors.toList());
						if (ebList.size() > 0) {
							employeeIdNo = ebList.get(0).getEmployeeId();
							employeeNo = ebList.get(0).getEmployeeNo();
						} else {
							stringBuilder.append("员工号不存在,");
						}
					} else {
						stringBuilder.append("员工号不能为空,");
					}

					// 验证日期内，考勤时间是否相同
					if (date != null) {
						// 验证班次年份和月份和日期是否符合
						Calendar cal = Calendar.getInstance();
						cal.setTime(date);
						int year = cal.get(Calendar.YEAR);
						int month = cal.get(Calendar.MONTH) + 1;
						if (schedulWeekBean.getYear() != null && year != schedulWeekBean.getYear().intValue()) {
							stringBuilder.append("班次年份(" + schedulWeekBean.getYear() + ")与日期年(" + year + ")不一致,");
						}
						if (schedulWeekBean.getMonth() != null && month != schedulWeekBean.getMonth().intValue()) {
							stringBuilder.append("班次月份(" + schedulWeekBean.getMonth() + ")与日期月(" + month + ")不一致,");
						}

						Date de = date;
						// 添加并验证日期，如果日期相同，将员工合并在到List集合中
						List<EmployeePunchTimeBean> eprbList = employeePunchTimeBeanList.stream()
								.filter(s -> s.getDate().equals(de)).collect(Collectors.toList());
						if (eprbList.size() > 0) {
							if (punchTimeId != null) {
								Integer ptId = punchTimeId;
								// 验证考勤时间是否一致
								List<EmployeePunchTimeBean> epList = eprbList.stream()
										.filter(s -> s.getPunchTimeId().equals(ptId)).collect(Collectors.toList());
								if (epList.size() <= 0) {
									stringBuilder.append("该日期(" + ToolUtils.dateToStr(de) + ")-考勤时间必须一致,");
								}
							}
						}

						Integer eId = employeeIdNo;
						// 验证日期内，是否重复员工
						if (eprbList.size() > 0) {
							List<EmployeeBean> ebList = eprbList.get(0).getEmployeeList().stream()
									.filter(s -> s.getEmployeeId().equals(eId)).collect(Collectors.toList());
							if (ebList.size() > 0) {
								stringBuilder
										.append("相同日期(" + ToolUtils.dateToStr(de) + ")-员工号(" + employeeNo + ")重复,");
							}
						}
						// 验证是否已经存在无规律班次
						if (eId != null) {
							List<EmployeeSchedul> esList = employeeSchedulList.stream()
									.filter(s -> s.getEmployeeId().equals(eId) && s.getFromDate().equals(de)
											&& s.getThruDate().equals(de))
									.collect(Collectors.toList());
							if (esList.size() > 0) {
								List<SchedulWeek> swList = schedulWeekList.stream()
										.filter(s -> s.getSwId().equals(esList.get(0).getSwId()))
										.collect(Collectors.toList());
								if (swList.size() > 0) {
									stringBuilder.append("该日期(" + ToolUtils.dateToStr(de) + ")-员工号(" + employeeNo
											+ ")已存在班次(" + swList.get(0).getSwName() + "),");
								}
							}
						}
					}

					// 判断错误信息长度
					if (stringBuilder.length() != new String("第" + (i + 1) + "行：").length()) {
						String errorStr = stringBuilder.toString().substring(0, stringBuilder.toString().length() - 1);
						errorMsgList.add(errorStr);
					} else {
						Date de = date;
						boolean type = true;
						// 添加并验证日期，如果日期相同，将员工合并在到List集合中
						for (EmployeePunchTimeBean eprbList : employeePunchTimeBeanList) {
							if (eprbList.getDate() != null && de != null) {
								if (eprbList.getDate().equals(de)) {
									List<EmployeeBean> employeeList = eprbList.getEmployeeList();
									employeeBean = new EmployeeBean();
									employeeBean.setEmployeeId(employeeIdNo);
									employeeList.add(employeeBean);
									eprbList.setEmployeeList(employeeList);
									type = false;
									break;
								}
							}
						}
						if (type) {
							EmployeePunchTimeBean employeePunchTimeBean = new EmployeePunchTimeBean();
							employeePunchTimeBean.setDate(date);
							employeePunchTimeBean.setPunchTimeId(punchTimeId);
							employeePunchTimeBean.setCheckbox(true);
							List<EmployeeBean> employeeList = new ArrayList<EmployeeBean>();
							employeeBean = new EmployeeBean();
							employeeBean.setEmployeeId(employeeIdNo);
							employeeList.add(employeeBean);
							employeePunchTimeBean.setEmployeeList(employeeList);
							employeePunchTimeBeanList.add(employeePunchTimeBean);
						}
					}
				}

				if (errorMsgList.size() > 0) {
					throw new ResultFaultException("5_00010", errorMsgList);
				} else {
					// 排序
					List<EmployeePunchTimeBean> eptList = employeePunchTimeBeanList.stream()
							.sorted(Comparator.comparing(EmployeePunchTimeBean::getDate)).collect(Collectors.toList());
					schedulWeekBean.setFromDate(eptList.get(0).getDate());
					schedulWeekBean.setThruDate(eptList.get(eptList.size() - 1).getDate());
					schedulWeekBean.setEmployeePunchTimeList(employeePunchTimeBeanList);
					// 保存
					this.saveSchedulWeek(schedulWeekBean, false);
				}
				successList.add(0, "导入完成。");
				return successList;
			}
		}
		throw new ResultFaultException("0_00014");
	}

	/**
	 * 员工明细导出
	 * 
	 * @param schedulWeekBean
	 * @return
	 */
	@SuppressWarnings("resource")
	@Override
	public String exportSchedulWeek(SchedulWeekBean schedulWeekBean) {
		try {
			long time = System.currentTimeMillis();
			String readUrl = AppConstant.TEMPLATEFILEREPOSITORY + "/班次员工明细.xlsx";
			String fileurl = AppConstant.REPORTFILEREPOSITORY + "/班次员工明细" + time + ".xlsx";
			String url = AppConstant.REPORT_RESOURCE + "/班次员工明细" + time + ".xlsx";
			File file = new File(readUrl);
			if (!file.exists()) {
				try {
					file.createNewFile();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			InputStream inputStream = new FileInputStream(readUrl);
			Workbook wb = null;
			if (readUrl.matches("^.+\\.(?i)(xls)$")) {
				wb = new HSSFWorkbook(inputStream);
			} else if (readUrl.matches("^.+\\.(?i)(xlsx)$")) {
				wb = new XSSFWorkbook(inputStream);
			} else {
				throw new ResultFaultException("8_00001");
			}
			Sheet sheet = wb.getSheetAt(0);

			// 创建单元格样式对象
			XSSFCellStyle ztStyle = (XSSFCellStyle) wb.createCellStyle();

			// 设置字体样式
			Font ztFont = wb.createFont();
			ztFont.setFontHeightInPoints((short) 9); // 将字体大小设置为18px
			ztFont.setFontName("微软雅黑"); // 将“华文行楷”字体应用到当前单元格上
			ztStyle.setFont(ztFont);
			// 设置边框颜色
			ztStyle.setBorderBottom(CellStyle.BORDER_THIN);
			ztStyle.setBorderTop(CellStyle.BORDER_THIN);
			ztStyle.setBorderLeft(CellStyle.BORDER_THIN);
			ztStyle.setBorderRight(CellStyle.BORDER_THIN);

			// 设置单元格边框颜色
			XSSFColor ztColor = new XSSFColor(java.awt.Color.black);
			ztStyle.setBottomBorderColor(ztColor);
			ztStyle.setTopBorderColor(ztColor);
			ztStyle.setLeftBorderColor(ztColor);
			ztStyle.setRightBorderColor(ztColor);

			// 查询班次
			SchedulWeek schedulWeek = schedulWeekDao.selectByPrimaryKey(schedulWeekBean.getSwId());
			// 设置班次名称
			Row row = sheet.getRow(0);
			Cell cell = row.getCell(1);
			cell.setCellValue(schedulWeek.getSwName());

			// 查询班次员工明细集合
			List<EmployeeBean> employeeBeanList = this.getSchedulWeekEmployeeDetailedList(schedulWeekBean.getSwId());
			for (int i = 0; i < employeeBeanList.size(); i++) {
				EmployeeBean employeeBean = employeeBeanList.get(i);
				if (employeeBean == null) {
					continue;
				}
				// 列号
				int columns = 0;
				row = sheet.createRow(3 + i);
				// 开始日期
				cell = row.createCell(columns);
				cell.setCellStyle(ztStyle);
				if (employeeBean.getFromDate() != null) {
					cell.setCellValue(ToolUtils.dateToStr(employeeBean.getFromDate()));
				}
				// 结束日期
				columns++;
				cell = row.createCell(columns);
				cell.setCellStyle(ztStyle);
				if (employeeBean.getThruDate() != null) {
					cell.setCellValue(ToolUtils.dateToStr(employeeBean.getThruDate()));
				}
				// 签到时间
				columns++;
				cell = row.createCell(columns);
				cell.setCellStyle(ztStyle);
				if (employeeBean.getStartFromTime() != null && employeeBean.getStartToTime() != null) {
					cell.setCellValue(employeeBean.getStartFromTime() + "-" + employeeBean.getStartToTime());
				}
				// 末班签退
				columns++;
				cell = row.createCell(columns);
				cell.setCellStyle(ztStyle);
				if (employeeBean.getEndFromTime() != null && employeeBean.getEndToTime() != null) {
					cell.setCellValue(employeeBean.getEndFromTime() + "-" + employeeBean.getEndToTime());
				}
				// 员工号
				columns++;
				cell = row.createCell(columns);
				cell.setCellStyle(ztStyle);
				if (employeeBean.getEmployeeNo() != null) {
					cell.setCellValue(employeeBean.getEmployeeNo());
				}
				// 姓名
				columns++;
				cell = row.createCell(columns);
				cell.setCellStyle(ztStyle);
				if (employeeBean.getChineseName() != null) {
					cell.setCellValue(employeeBean.getChineseName());
				}
				// 英文
				columns++;
				cell = row.createCell(columns);
				cell.setCellStyle(ztStyle);
				if (employeeBean.getEnglishName() != null) {
					cell.setCellValue(employeeBean.getEnglishName());
				}
				// 公司编码
				columns++;
				cell = row.createCell(columns);
				cell.setCellStyle(ztStyle);
				if (employeeBean.getCorporationCode() != null) {
					cell.setCellValue(employeeBean.getCorporationCode());
				}
				// 公司名称
				columns++;
				cell = row.createCell(columns);
				cell.setCellStyle(ztStyle);
				if (employeeBean.getCorporationName() != null) {
					cell.setCellValue(employeeBean.getCorporationName());
				}
				// 部门编码
				columns++;
				cell = row.createCell(columns);
				cell.setCellStyle(ztStyle);
				if (employeeBean.getDepartmentCode() != null) {
					cell.setCellValue(employeeBean.getDepartmentCode());
				}
				// 部门名称
				columns++;
				cell = row.createCell(columns);
				cell.setCellStyle(ztStyle);
				if (employeeBean.getDepartmentName() != null) {
					cell.setCellValue(employeeBean.getDepartmentName());
				}

				// 岗位集合
				List<String> roleList = new ArrayList<String>();
				List<RoleBean> roleBeanList = employeeBean.getRoleList();
				for (RoleBean roleBean : roleBeanList) {
					roleList.add(roleBean.getRoleCode() + "/" + roleBean.getRoleName());
				}
				// 岗位
				columns++;
				cell = row.createCell(columns);
				// XSSFCellStyle cellStyle=(XSSFCellStyle)ztStyle;
				// cellStyle.setWrapText(true);
				cell.setCellStyle(ztStyle);
				if (roleList.size() > 0) {
					String content = String.join("\n", roleList);
					cell.setCellValue(content);
				}
			}
			FileOutputStream outStream = new FileOutputStream(fileurl);
			wb.write(outStream);
			outStream.close();
			return url;
		} catch (Exception e) {
			return null;
		}
	}

}
